const db = require('../db/index')
exports.login = (req, res) => {
    // res.send('登录')
    const userinfo = req.body
        // console.log(userinfo);
        // res.send(userinfo)
    const sql = 'select * from user where username=?'
    db.query(sql, userinfo.username, (err, results) => {
        if (err) return res.send(err.message)
        if (results.length !== 1) return res.send({ status: 201, message: '登录失败,用户名错误' })
        if (results[0].password !== userinfo.password) {
            return res.send({ status: 201, message: '登录失败，密码错误' })
        }
        res.send({
            status: 200,
            message: '登录成功',
            data: userinfo
        })

    })
}